package com.keba.lamp.ai.controller;

import com.keba.basic.base.R;
import com.keba.basic.interfaces.echo.EchoService;
import com.keba.basic.utils.BeanPlusUtil;
import com.keba.lamp.ai.entity.AiApplication;
import com.keba.lamp.ai.service.AiApplicationService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import com.keba.basic.base.controller.SuperController;
import com.keba.lamp.ai.service.AiInvokeRecordService;
import com.keba.lamp.ai.entity.AiInvokeRecord;
import com.keba.lamp.ai.vo.save.AiInvokeRecordSaveVO;
import com.keba.lamp.ai.vo.update.AiInvokeRecordUpdateVO;
import com.keba.lamp.ai.vo.result.AiInvokeRecordResultVO;
import com.keba.lamp.ai.vo.query.AiInvokeRecordPageQuery;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * <p>
 * 前端控制器
 * ai调用记录表
 * </p>
 *
 * @author twg
 * @date 2025-03-12 22:09:15
 * @create [2025-03-12 22:09:15] [twg] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/aiInvokeRecord")
@Tag(name = "ai调用记录表")
public class AiInvokeRecordController extends SuperController<AiInvokeRecordService, Long, AiInvokeRecord
        , AiInvokeRecordSaveVO, AiInvokeRecordUpdateVO, AiInvokeRecordPageQuery, AiInvokeRecordResultVO> {
    private final EchoService echoService;

    private final AiApplicationService aiApplicationService;

    @Override
    public EchoService getEchoService() {
        return echoService;
    }


    @Override
    public R<AiInvokeRecordResultVO> getDetail(Long aLong) {
        AiInvokeRecord aiInvokeRecord = superService.getById(aLong);
        AiInvokeRecordResultVO aiInvokeRecordResultVO = BeanPlusUtil.toBean(aiInvokeRecord, AiInvokeRecordResultVO.class);
        AiApplication aiApplication = aiApplicationService.getById(aiInvokeRecordResultVO.getApplicationId());
        if (Objects.nonNull(aiApplication)) {
            aiInvokeRecordResultVO.getEchoMap().putIfAbsent("applicationId", aiApplication.getName());
        }
        return R.success(aiInvokeRecordResultVO);
    }
}


